package com.ct.controller.shipping;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ct.application.commons.vo.StatusRequest;
import com.ct.application.shipping.model.po.ChuanYuanKuPeiXunSavePO;
import com.ct.application.shipping.model.po.ChuanYuanKuPeiXunSearchPO;
import com.ct.application.shipping.model.vo.ChuanYuanKuPeiXunVO;
import com.ct.application.shipping.service.ChuanYuanKuPeiXunService;
import com.ct.commons.BaseController;
import com.ct.commons.annotation.ApiLog;
import com.ct.commons.annotation.HasAdmin;
import com.ct.commons.annotation.PermissionApi;
import com.ct.commons.aspect.limiter.AccessIpLimiter;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * 船员证书-培训项目配置
 * @author Auto Generator
 * @since 2023-08-16
 */
@RestController
@PermissionApi(title = "船员证书-培训项目",path="/api/v1/chuanyuankupeixun",code = "N1000",sorted = 16)
public class ChuanYuanKuPeiXunController extends BaseController {

    @Resource
    private ChuanYuanKuPeiXunService chuanYuanFenZuService;

    /**
     * 查询船员证书-培训项目列表
     * @param chuanYuanFenZuSearchPO
     * @return
     */
    @PostMapping("/chuanyuankupeixun/list")
    @PermissionApi(title = "查询船员证书-培训项目列表",path="/api/v1/chuanyuankupeixun/list",code = "N1001",sorted = 1)
    public Page<ChuanYuanKuPeiXunVO> findChuanYuanKuPeiXuns(@Validated @RequestBody ChuanYuanKuPeiXunSearchPO chuanYuanFenZuSearchPO) {
        return chuanYuanFenZuService.findChuanYuanKuPeiXun(chuanYuanFenZuSearchPO);
    }

    /**
     * 保存和更新
     *
     * @param savePO
     * @return
     */
    @PostMapping("/chuanyuankupeixun/saveupdate")
    @ApiLog("船员证书-培训项目保存和更新")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "船员证书-培训项目保存和更新",path="/api/v1/chuanyuankupeixun/saveupdate",code = "N1003",sorted = 3)
    public ChuanYuanKuPeiXunVO saveUpdateChuanYuanKuPeiXun(@Validated @RequestBody ChuanYuanKuPeiXunSavePO savePO) {
        if (Objects.nonNull(savePO.getId())){
            return chuanYuanFenZuService.updateChuanYuanKuPeiXun(savePO);
        }else {
            return chuanYuanFenZuService.saveChuanYuanKuPeiXun(savePO);
        }
    }

    /**
     * 根据id查询船员证书-培训项目
     *
     * @param id
     * @return
     */
    @PostMapping("/chuanyuankupeixun/get/{id}")
    @PermissionApi(title = "根据id查询船员证书-培训项目",path="/api/v1/chuanyuankupeixun/get/{id}",code = "N1004",sorted = 4)
    public ChuanYuanKuPeiXunVO getChuanYuanKuPeiXunById(@PathVariable("id") Long id) {
        return chuanYuanFenZuService.getChuanYuanKuPeiXun(id);
    }


    /**
     * 根据id删除船员证书-培训项目
     *
     * @param id
     * @return
     */
    @PostMapping("/chuanyuankupeixun/del/{id}")
    @ApiLog("根据id删除船员证书-培训项目")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "根据id删除船员证书-培训项目",path="/api/v1/chuanyuankupeixun/del/{id}",code = "N1005",sorted = 5)
    public Boolean delChuanYuanKuPeiXunById(@PathVariable("id") Long id) {
        return chuanYuanFenZuService.delChuanYuanKuPeiXun(id);
    }

    /**
     * 修改状态
     *
     * @return
     */
    @PostMapping("/chuanyuankupeixun/update/status")
    @ApiLog("船员证书-培训项目修改状态")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "船员证书-培训项目修改状态",path="/api/v1/chuanyuankupeixun/update/status",code = "N1006",sorted = 6)
    public Boolean updateStatus(@Validated @RequestBody StatusRequest statusRequest) {
        return chuanYuanFenZuService.updateStatus(statusRequest);
    }
}
